import * as req from '@/request';

export async function list(
  params?: { [key: string]: any },
  sorter?: { [key: string]: any },
  filter?: { [key: string]: any },
) {
  console.log(
    'user.list params:',
    params,
    ' sorter:',
    sorter,
    ' filter:',
    filter,
  );
  return req.postForm<API.UserList>('/user/list', params, sorter, filter);
}

export async function get(id: string) {
  return req.get<API.UserForm>(`/user/get/${id}`);
}

export async function update(data: { [key: string]: any }) {
  return req.postForm<API.Result>('/user/update', data);
}

export async function remove(data: { key: string }) {
  return req.post<API.Result>('/user/delete', data);
}

export async function changePassword(data: { [key: string]: any }) {
  return req.postForm<API.Result>('/user/changepassword', data);
}

export async function auth(data: { [key: string]: any }) {
  return req.postForm<API.Result>('/user/auth', data);
}

export async function getDevices(
  params?: { [key: string]: any },
  sorter?: { [key: string]: any },
  filter?: { [key: string]: any },
) {
  return req.postForm<API.UserDeviceList>(
    '/user/getDevices',
    params,
    sorter,
    filter,
  );
}

export async function removeDevice(data: { key: string }) {
  return req.post<API.Result>('/user/deleteDevice', data);
}
